<?php
/**
 * Created by JetBrains PhpStorm.
 * User: nietao
 * Date: 13-10-11
 * Time: 下午1:50
 * To change this template use File | Settings | File Templates.
 */
namespace Forxx;

use Lavender\Core;

class MemCache
{

    protected $cache;

    // session interface
    // public function set($id, $data, $time)
    // public function update_time($id, $time)
    // public function delete($id)
    // public function get_raw_record($id)
    public function __construct()
    {
        $this->cache = new \Memcache();
        $config = Core::get_config('cache', 'memcache');
        $this->cache->connect($config['host'], $config['port']);
    }

    public function set($id, $data, $time)
    {
        $value = array(
            'data' => $data,
            'updated' => $time
        );
        $this->cache->set($id, $value);
    }

    public function update_time($id, $time)
    {
        $value = $this->cache->get($id);
        $value['updated'] = $time;
        $this->cache->replace($id, $value);
    }

    public function delete($id)
    {
        $this->cache->delete($id);
    }

    public function get_raw_record($id)
    {
        return $this->cache->get($id);
    }
}